<!DOCTYPE html>
<html lang="en" >
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="author" content="GoJun" />
	
	
	
	<title>面试官问我：如何对 Android  App 进行 fps 分析 ｜ GoJun</title>
	
    
    
    <meta name="description" content="背景 界面呈现是指从应用生成帧并将其显示在屏幕上的动作。要确保用户能够流畅地与您的应用互动，您的应用呈现每帧的时间不应超过 16ms，以达到每秒 60 帧的呈现速度。 结论动画控制在每帧耗时 16ms 以下，因此需要进行 FPS" />
    

    
    
    <meta name="keywords" content="Hugo, theme, zozo" />
    

	
    
    <link rel="shortcut icon" href="https://gojun.me/images/favicon.ico" />

    <link rel="stylesheet" type="text/css" media="screen" href="https://gojun.mecss/normalize.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://cdn.jsdelivr.net/npm/animate.css@4.1.0/animate.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://gojun.me/css/zozo.css" />
	<link rel="stylesheet" type="text/css" media="screen" href="https://cdn.jsdelivr.net/npm/remixicon@2.5.0/fonts/remixicon.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://gojun.me/css/highlight.css" />

    
    
</head>

<body>
    <div class="main animate__animated animate__fadeInDown">
        <div class="nav_container animated fadeInDown">
    <div class="site_nav" id="site_nav">
        <ul>
            
            <li>
                <a href="/">Home</a>
            </li>
            
            <li>
                <a href="/posts/">Archive</a>
            </li>
            
            <li>
                <a href="/tags/">Tags</a>
            </li>
            
            <li>
                <a href="/projects/">Projects</a>
            </li>
            
        </ul>
    </div>
    <div class="menu_icon">
        <a id="menu_icon"><i class="ri-menu-line"></i></a>
    </div>
</div>
        <div class="header animated fadeInDown">
    <div class="site_title_container">
        <div class="site_title">
            <h1>
                <a href="https://gojun.me">
                    <span>GoJun</span>
                </a>
            </h1>
        </div>
        <div class="description">
            <p class="sub_title">为向往生活努力奋斗！</p>
            <div class="my_socials">
                
                
                <a href="https://github.com/freelander" title="github" target="_blank"><i class="ri-github-fill"></i></a>
                
                
                <a href="https://gojun.me/index.xml" type="application/rss+xml" title="rss" target="_blank"><i
                        class="ri-rss-fill"></i></a>
            </div>
        </div>
    </div>
</div>
        <div class="content">
            <div class="post_page">
                <div class="post animate__animated animate__fadeInDown">
                    <div class="post_title post_detail_title">
                        <h2><a href='/posts/android-fps/'>面试官问我：如何对 Android  App 进行 fps 分析</a></h2>
                        <span class="date">2021.01.06</span>
                    </div>
                    <div class="post_content markdown"><h3 id="背景">背景</h3>
<p>界面呈现是指从应用生成帧并将其显示在屏幕上的动作。要确保用户能够流畅地与您的应用互动，您的应用呈现每帧的时间不应超过 16ms，以达到每秒 60 帧的呈现速度。</p>
<blockquote>
<p>结论动画控制在每帧耗时 16ms 以下，因此需要进行 FPS 分析。</p>
</blockquote>
<h3 id="前提">前提</h3>
<p>进行分析前，手机先开启 <code>GPU呈现模式分析</code>。</p>
<blockquote>
<p>打开手机“设置”-“更多设置”-“开发者选项”-“GPU 呈现模式分析”，选中“在adb shell dumpsys gfinfo”中</p>
</blockquote>
<p>设置路径基本都一样，都是在开发者选项里，部分手机是叫做 “HWUI 呈现模式分析”，下图是小米手机截图。</p>
<p>

<div class="fancybox">
<a data-fancybox="demo" href="/images/2021/01/android_fps_01.png">
<img src="/images/2021/01/android_fps_01.png" alt="image"  />
</a>
</div>

</p>
<h3 id="打开测试的界面">打开测试的界面</h3>
<p>先打开你要进行分析的界面，然后再终端输入以下命令。</p>
<h3 id="命令">命令</h3>
<p>利用 <a href="https://developer.android.com/studio/command-line/dumpsys?hl=zh-cn#ui">dumpsys</a> 获取当前指定 App 发生的动画帧相关的性能信息，并以 txt 文件保存下来。</p>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">adb shell dumpsys gfxinfo package-name &gt; loading.txt 
</code></pre></div><h4 id="遇到问题">遇到问题</h4>
<p>执行命令出现错误</p>
<div class="highlight"><pre class="chroma"><code class="language-fallback" data-lang="fallback">adb E  1250 22834 usb_osx.cpp:327] Could not open interface: e00002c5
adb E  1250 22834 usb_osx.cpp:289] Could not find device interface
error: could not install *smartsocket* listener: Address already in use
ADB server didn&#39;t ACK
* failed to start daemon *
error: cannot connect to daemon
</code></pre></div><blockquote>
<p>解决：打开 Mac 活动监视器在 内存 栏，找到 adb 进程，对它进行强制退出</p>
</blockquote>
<h3 id="导入-excel">导入 Excel</h3>
<h4 id="第一步导入文本">第一步导入文本</h4>
<p>

<div class="fancybox">
<a data-fancybox="demo" href="/images/2021/01/android_fps_02.png">
<img src="/images/2021/01/android_fps_02.png" alt="image"  />
</a>
</div>

</p>
<h4 id="第二步完成导入">第二步完成导入</h4>
<p>这一步直接点击 <strong>完成</strong> 即可，然后点击 <strong>确定</strong> 。</p>
<p>

<div class="fancybox">
<a data-fancybox="demo" href="/images/2021/01/android_fps_03.png">
<img src="/images/2021/01/android_fps_03.png" alt="image"  />
</a>
</div>

</p>
<p>

<div class="fancybox">
<a data-fancybox="demo" href="/images/2021/01/android_fps_04.png">
<img src="/images/2021/01/android_fps_04.png" alt="image"  />
</a>
</div>

</p>
<h4 id="第三步复制耗帧数据">第三步复制耗帧数据</h4>
<p>找到对应需要分析的界面类的数据，比如我这边的：</p>
<p>

<div class="fancybox">
<a data-fancybox="demo" href="/images/2021/01/android_fps_05.png">
<img src="/images/2021/01/android_fps_05.png" alt="image"  />
</a>
</div>

</p>
<p>将这块数据复制到新建一份 <strong>工作表</strong>。</p>
<p>

<div class="fancybox">
<a data-fancybox="demo" href="/images/2021/01/android_fps_06.png">
<img src="/images/2021/01/android_fps_06.png" alt="image"  />
</a>
</div>

</p>
<h3 id="折线图分析">折线图分析</h3>
<p>在新建的工作表最后新增一栏命名为 <strong>每秒耗帧（毫秒）</strong></p>
<p>进行自动求和操作，选中新增栏的标题下一格，然后点击 Excel 表中的 <strong>开始 》 自动求和</strong>，这时会出现计算公式，直接按下回车键即计算出当前行的值总和，接着往下拉会自动进行每行的求和操作。</p>
<p>对  <strong>每秒耗帧（毫秒）</strong> 栏进行图表分析：</p>
<p>

<div class="fancybox">
<a data-fancybox="demo" href="/images/2021/01/android_fps_07.png">
<img src="/images/2021/01/android_fps_07.png" alt="image"  />
</a>
</div>

</p>
<p>接着就会自动生成一份图表：</p>
<p>

<div class="fancybox">
<a data-fancybox="demo" href="/images/2021/01/android_fps_08.png">
<img src="/images/2021/01/android_fps_08.png" alt="image"  />
</a>
</div>

</p>
<blockquote>
<p>分析图表的趋势，如果每帧耗时在 <strong>16ms</strong> 以上，那么即需要优化。</p>
</blockquote>
<h3 id="相关链接">相关链接</h3>
<ul>
<li><a href="https://developer.android.com/topic/performance/vitals/render.html">渲染速度缓慢</a></li>
<li><a href="https://developer.android.com/topic/performance/rendering/inspect-gpu-rendering#profile_rendering">分析 GPU 渲染速度</a></li>
<li><a href="https://juejin.im/post/6844904161746616334">面试官问我：Android APP中如何测试FPS？看我如何分析京东，拼多多App的FPS</a></li>
<li><a href="https://lottiefiles.com/">Lottie 动画预览</a></li>
<li><a href="https://developer.android.com/studio/command-line/dumpsys?hl=zh-cn">dumpsys</a></li>
<li><a href="https://developer.android.com/training/testing/performance?hl=zh-cn">测试界面性能</a></li>
</ul>
</div>
                    <div class="post_footer">
                        
                        <div class="meta">
                            <div class="info">
                                <span class="field tags">
                                    <i class="ri-stack-line"></i>
                                    
                                    <a href="https://gojun.me/tags/android/">Android</a>
                                    
                                </span>
                            </div>
                        </div>
                        
                    </div>
                </div>
                
                
                <div class="doc_comments"></div>
                
            </div>
        </div>
    </div>
    <a id="back_to_top" href="#" class="back_to_top"><i class="ri-arrow-up-s-line"></i></a>
    <footer class="footer">
    <div class="footer_slogan">
        <span></span>
    </div>
</footer>
    <script src="https://gojun.me/js/jquery-3.5.1.min.js"></script>
<link href="https://gojun.me/css/fancybox.min.css" rel="stylesheet">
<script src="https://gojun.me/js/fancybox.min.js"></script>
<script src="https://gojun.me/js/zozo.js"></script>


<script type="text/javascript" async
    src="https://cdn.bootcss.com/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
        MathJax.Hub.Config({
            tex2jax: {
                inlineMath: [['$', '$'], ['\\(', '\\)']],
                displayMath: [['$$', '$$'], ['\[\[', '\]\]']],
                processEscapes: true,
                processEnvironments: true,
                skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
                TeX: {
                    equationNumbers: { autoNumber: "AMS" },
                    extensions: ["AMSmath.js", "AMSsymbols.js"]
                }
            }
        });

        MathJax.Hub.Queue(function () {
            
            
            
            var all = MathJax.Hub.getAllJax(), i;
            for (i = 0; i < all.length; i += 1) {
                all[i].SourceElement().parentNode.className += ' has-jax';
            }
        });
    </script>

<style>
    code.has-jax {
        font: inherit;
        font-size: 100%;
        background: inherit;
        border: inherit;
        color: #515151;
    }
</style>



<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
	window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
	ga('create', 'UA-142037913-1', 'auto');
	
	ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>

</body>

</html>